﻿@{
    ViewBag.Title = "选择源系统";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
        var retArr = new Array();
        var ExpIDs = new Array();
        var selectCount = -1;
        var opts = {
            rows: 10,
            height: 450,
            url: "/SystemConfiguration/EtlSourceList",
            para: { dbName: encodeURI(UrlArray["dbName"]) },
            idField: "GUID",
            checkbox: true,
            columns: [
                    { field: 'SourceSysName', title: '系统名称', width: 25, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            return value;
                            //return "<a href='/SystemConfiguration/EtlSourceViewConfig/?systemID=" + rowData.GUID + "&dbName=" + encodeURI(UrlArray["dbName"]) + "'>" + value + "</a>";
                        }
                    },
                    { field: 'SourceTypeStr', title: '数据库类型', width: 15, align: 'center', sortable: true },
                    { field: 'SourceSysDescription', title: '描述', width: 30, sortable: true },
                    { field: 'StatusStr', title: '状态', width: 8, align: 'center', sortable: true },
                    { field: 'ETLStatus', title: '任务状态', width: 10, sortable: true, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            if (value == 2)
                                return "<img src='/images/stepok.png' />";
                            else
                                return "<img src='/images/steperr.png' />";
                        }
                    },
                    { field: 'CreateTime', title: '创建时间', width: 12, align: 'center', sortable: true }
                ],
            OnChickRow: function (value, rowData, rowIndex) {
                var s = true;
                if (selectCount > -1 && ExpIDs.length >= selectCount) {
                    alert("只可选择 " + selectCount + " 个，请检查选择项。");
                    s = false;
                    return false;
                }
                if (s) {
                    $("#sel_content").append("<span class='s1 s1" + value + "'><a title='" + rowData.SourceSysDescription + "'>" + rowData.SourceSysName + "</a><span class='s2 s2" + value + "''>&nbsp;X&nbsp;</span></span>");

                    $(".s2" + value).bind("click", function () {
                        $(".s1" + value).remove();
                        $(".s2" + value).remove();
                        for (var j = 0; j < retArr.length; j++) {
                            if (retArr[j].GUID == value) {
                                retArr.removeAt(j);
                            }
                        }
                        ExpIDs.removeValue(value);
                        opts.para["ExpIDs"] = ExpIDs.join(",");
                        initTable("DataGrid2", opts);
                    });
                    retArr.push(rowData);
                    ExpIDs.push(value);
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid2", opts);
                    return true;
                }
            }
        };
        $(function () {
            selectCount = UrlArray["selectCount"];
            page_Init();
            InitList();
        });
        function page_Init() {
            $("body").css("overflow", "hidden");
        }
        function DoAction(i, v) {
            var arr = new Array();
            arr.push(i);
            arr.push(v);
            returnParent(arr);
        }
        function InitList() {
            opts.para["name"] = $("#txtName").val();
            $("#DataGrid2").dg(opts);
        }
        function btnSearch() {
            InitList();
        }
        function flexiSelect() {
            if (retArr.length < 1) {
                alert('请选择一条数据!');
                return false;
            }
            if (selectCount > -1 && retArr.length > selectCount) {
                alert("只可选择 " + selectCount + " 个，请检查选择项。");
                return false;
            }
            returnParent(retArr);
            return false;
        }
    </script>
}
<div style="height: 470px; padding-left: 5px; padding-right: 5px; overflow: hidden;
    overflow-y: auto;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                源系统搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                源系统名称：
                <input type="text" id="txtName" style="width: 300px;" />
                <input type="button" value="搜索" class="button" onclick="btnSearch()" />
            </td>
        </tr>
    </table>
    <table id="selected" style="width: 100%;">
        <tr>
            <td width="50">
                已选择：
            </td>
            <td>
                <div id="sel_content">
                </div>
            </td>
            <td width="50">
                <input type="button" value=" 确定 " class="button" onclick="flexiSelect()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                源系统列表<span id="type_Name"></span>
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table id="DataGrid2" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
